package logic

import (
	"context"
	"house/bookingrpc/bookingrpc"

	"house/api/internal/svc"
	"house/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookingAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBookingAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookingAddLogic {
	return &BookingAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BookingAddLogic) BookingAdd(req *types.BookingAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.BookingRpc.BookingAdd(l.ctx, &bookingrpc.BookingAddRequest{
		Address: req.Address,
		Types:   req.Types,
		Time:    req.Time,
		Contact: req.Contact,
		HouseId: req.HouseId,
		UserId:  req.UserId,
		Status:  "预约中",
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "看房预约添加成功",
		Data:    add,
	}, nil
}
